package org.zsqx.tools;

import java.lang.reflect.Field;

import org.zsqx.action.WarnReportAction;
import org.zsqx.bean.SumReports;
import org.zsqx.bean.WarnSet;

import cDao.HelpDao;

public class ReportTools {
	private static final String OVER_COLOR = "red";
	private static final String UNDER_COLOR = "green";
	public static String getReportTownTitle(SumReports report){
		String year = "";
		String month = report.getMonth();
		if(null!=report.getYear()){
			year = report.getYear();
		}else{
			year = report.getTimeStage();
		}
		String reportTitle = "镇区";
		if(report.getDstype()!=null){
			reportTitle += report.getDstype()+"灾害";
		}else {
			reportTitle += "所有灾害";
		}
		if(null!=year){
			reportTitle += year+"年";
		}else {
			reportTitle += "全部";
		}
		if(report.getStartYear()!=null){
			reportTitle += report.getStartYear()+"年至"+report.getEndYear()+"年";
		}
		if(null!=month){
			reportTitle += month+"月份";
		}
		reportTitle+="灾害统计报表";
		return reportTitle;
	}
	public static String getReportMonthTitle(SumReports report){
		String year = report.getYear();
		String month = report.getMonth();
		String reportTitle ="";
		if(report.getTown()!=null){
			reportTitle += report.getTown();
		}else {
			reportTitle += "所有镇区";
		}
		if(null!=year){
			reportTitle += year+"年";
		}else {
			reportTitle += "所有年";
		}
		if(null!=month){
			reportTitle += month+"月份";
		}
		reportTitle+="灾害统计报表";
		return reportTitle;
	}
	public static String colorString(Double value,String propertyName){
		PropertiesTools pt = new PropertiesTools();
		WarnSet warnSet = null;
		if(WarnReportAction.ws!=null){
			warnSet = WarnReportAction.ws;
		}else{
			warnSet = (WarnSet) pt.getPropertyesBean(new WarnSet());
		}
		Object beanValue = HelpDao.methodInvoke(WarnSet.class, warnSet, HelpDao.getGetMethod(propertyName));
		if(beanValue!=null){
			Double keyValue = (Double)beanValue ;
			if(value>keyValue){
				return "<span style='color:"+OVER_COLOR+";font-weight:bold;'>"+value+"</span>";
			}else{
				return value.toString();
			}
		}else{
			return value.toString();
		}
	}
	public static String tempColorString(Double value,String propertyName){
		PropertiesTools pt = new PropertiesTools();
		WarnSet warnSet = (WarnSet) pt.getPropertyesBean(new WarnSet());;
		Double under = (Double) HelpDao.methodInvoke(WarnSet.class, warnSet, HelpDao.getGetMethod(propertyName+"Under"));
		Double over = (Double) HelpDao.methodInvoke(WarnSet.class, warnSet, HelpDao.getGetMethod(propertyName+"Over"));
		try {
			if(value>over){
				return "<span style='color:"+OVER_COLOR+";font-weight:bold;'>"+value+"</span>";
			}else if(value<under){
				return "<span style='color:"+UNDER_COLOR+";font-weight:bold;'>"+value+"</span>";
			}else{
				return value.toString();
			}
		} catch (Exception e) {
			return value.toString();
		}
	}
	public static String getWindLevel(Double wind){
		String level = "";
		if(wind>=0&&wind<=0.2){
			level = "0";
		}else if(wind>0.2&&wind<=1.5){
			level = "1";
		}else if(wind>1.5&&wind<=3.3){
			level = "2";
		}else if(wind>3.3&&wind<=5.4){
			level = "3";
		}else if(wind>5.4&&wind<=7.9){
			level = "4";
		}else if(wind>7.9&&wind<=10.7){
			level = "5";
		}else if(wind>10.7&&wind<=13.8){
			level = "6";
		}else if(wind>13.8&&wind<=17.1){
			level = "7";
		}else if(wind>17.1&&wind<=20.7){
			level = "8";
		}else if(wind>20.7&&wind<=24.4){
			level = "9";
		}else if(wind>24.4&&wind<=28.4){
			level = "10";
		}else if(wind>28.4&&wind<=32.6){
			level = "11";
		}else if(wind>32.6){
			level = "12";
		}
		return level;
	}
	public static void changeNull(Object bean){
		Class c = bean.getClass();
		Field[] fields = c.getDeclaredFields();
		for (Field field : fields) {
			String methodName = HelpDao.getGetMethod(field.getName());
			HelpDao.methodInvoke(c, bean, methodName);
		}
	}

}
